from frame_work.base_page import BasePage


class QuantityPage(BasePage):
    pay_button = 'id=>J_payBtn'
    pay_password = 'id=>password'
    pay_confirm = 'c=>subBtn'
    success_tips = 'c=>back'
    locator_pay_title = '一站互联--支付操作页面'
    tfx_locator_pay_title = '淘发现--支付操作页面'
    error_tips = 'x=>//*[@id="CheckPassword"]/dd/p[2]/label[2]/font'

    def click_pay_btn(self):
        inputs = self.find_multi_elements('t=>input')
        for input in inputs:
            value = input.get_attribute('type')
            if value == 'submit':
                self.driver.execute_script("$(arguments[0]).click()", input)
                break

    def tfx_click_pay_btn(self):
        inputs = self.find_multi_elements('t=>input')
        for input in inputs:
            value = input.get_attribute('type')
            if value == 'button':
                self.driver.execute_script("$(arguments[0]).click()", input)

    def input_password(self, text):
        self.type(self.pay_password, text)

    def click_confirm(self):
        self.click(self.pay_confirm)

    def get_success_tips(self):
        value = self.text(self.success_tips)
        return value

    def switch_password_frame(self, value):
        self.switch_frame(value)

    def wait_pay_title(self, seconds):
        self.web_driver_wait_title(seconds, self.locator_pay_title)

    def tfx_wait_pay_title(self, seconds):
        self.web_driver_wait_title(seconds, self.tfx_locator_pay_title)

    def get_error_tips(self):
        text = self.text(self.error_tips)
        return text
